package com.example.tomatotodo.model;

import static com.example.tomatotodo.model.TodoConstants.DEFAULT_COUNTDOWN_DURATION;
import static com.example.tomatotodo.model.TodoConstants.DEFAULT_CYCLE;
import static com.example.tomatotodo.model.TodoConstants.DEFAULT_GOAL_TARGET_TYPE;
import static com.example.tomatotodo.model.TodoConstants.DEFAULT_GOAL_TARGET_VALUE;
import static com.example.tomatotodo.model.TodoConstants.DEFAULT_REST_DURATION;
import static com.example.tomatotodo.model.TodoConstants.TIMER_MODE_COUNTDOWN;
import static com.example.tomatotodo.model.TodoConstants.TYPE_POMODORO;

import java.io.Serializable;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class TodoSettingDTO implements Serializable {
    private static final long serialVersionUID = 1L;
    
    private String title;
    private String type; // POMODORO（普通番茄钟）、GOAL（定目标）
    private String timerMode; // COUNTDOWN（倒计时）、UPTIME（正向计时）、NO_TIMER（不计时）
    private Integer countdownDuration; // 单次倒计时总时长（秒）, 默认25分钟（1500秒）, 非空
    private String goalDeadline; // 目标截止日期, 默认当日, 非空
    private String goalTargetType; // 目标维度 DURATION（完成时长）、TIMES（完成次数）, 默认DURATION, 非空
    private Integer goalTargetValue; // 目标值, 默认1, 非空
    private Integer restDuration; // 休息时长（秒）, 默认5分钟（300秒）, 非空
    private Integer cycle; // 待办循环轮数, 默认1, 非空

    public TodoSettingDTO() {
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = currentDate.format(dateFormatter);

        this.title = "";
        this.type = TYPE_POMODORO;
        this.timerMode = TIMER_MODE_COUNTDOWN;
        this.countdownDuration = DEFAULT_COUNTDOWN_DURATION;
        this.goalDeadline = formattedDate;
        this.goalTargetType = DEFAULT_GOAL_TARGET_TYPE;
        this.goalTargetValue = DEFAULT_GOAL_TARGET_VALUE;
        this.restDuration = DEFAULT_REST_DURATION;
        this.cycle = DEFAULT_CYCLE;
    }

    /**
     * 构造函数
     *
     * @param title             待办名称
     * @param type              待办类型, 可选: POMODORO（普通番茄钟）、GOAL（定目标）
     * @param timerMode         计时模式, 可选: COUNTDOWN（倒计时）、UPTIME（正向计时）、NO_TIMER（不计时）
     * @param countdownDuration 单次倒计时总时长（秒）, 为空时默认25分钟（1500秒）
     * @param goalDeadline      待办目标截止日期, 为空时默认当日
     * @param goalTargetType    目标维度, 可选: DURATION（完成时长）、TIMES（完成次数）, 为空时默认DURATION
     * @param goalTargetValue   目标值, 为空时默认1
     * @param restDuration      休息时长（秒）, 为空时默认5分钟（300秒）
     * @param cycle             待办循环轮数, 为空时默认1
     */
    public TodoSettingDTO(String title, String type, String timerMode, Integer countdownDuration,
                          String goalDeadline, String goalTargetType, Integer goalTargetValue,
                          Integer restDuration, Integer cycle) {
        LocalDate currentDate = LocalDate.now();
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String formattedDate = currentDate.format(dateFormatter);

        this.title = title;
        this.type = type;
        this.timerMode = timerMode;
        this.countdownDuration = (countdownDuration == null ? DEFAULT_COUNTDOWN_DURATION : countdownDuration);
        this.goalDeadline = (goalDeadline == null ? formattedDate : goalDeadline);
        this.goalTargetType = (goalTargetType == null ? DEFAULT_GOAL_TARGET_TYPE : goalTargetType);
        this.goalTargetValue = (goalTargetValue == null ? DEFAULT_GOAL_TARGET_VALUE : goalTargetValue);
        this.restDuration = (restDuration == null ? DEFAULT_REST_DURATION : restDuration);
        this.cycle = (cycle == null ? DEFAULT_CYCLE : cycle);
    }
}
